package se.curalia.slimcache;

/**
 * Represents a bounding box.
 */
public class BBOX {
    double Xmin,Xmax,Ymin,Ymax;

    public BBOX(double Xmin, double Ymin, double Xmax, double Ymax) {
        setValues(Xmin,Ymin,Xmax,Ymax);
    }

    public BBOX(String bbox) {
        String[] values = bbox.split(",");
        setValues(values[0], values[1],values[2],values[3]);
    }

    private void setValues(String Xmin, String Ymin, String Xmax, String Ymax) {
        setValues(Double.parseDouble(Xmin),
                Double.parseDouble(Ymin),
                Double.parseDouble(Xmax),
                Double.parseDouble(Ymax));
    }
    
    private void setValues(double Xmin, double Ymin, double Xmax, double Ymax) {
        this.Xmin = Xmin;
        this.Xmax = Xmax;
        this.Ymin = Ymin;
        this.Ymax = Ymax;
    }

    public double getXmin() {
        return Xmin;
    }

    public void setXmin(double xmin) {
        Xmin = xmin;
    }

    public double getXmax() {
        return Xmax;
    }

    public void setXmax(double xmax) {
        Xmax = xmax;
    }

    public double getYmin() {
        return Ymin;
    }

    public void setYmin(double ymin) {
        Ymin = ymin;
    }

    public double getYmax() {
        return Ymax;
    }

    public void setYmax(double ymax) {
        Ymax = ymax;
    }

    public String toString() {
        StringBuffer sb = new StringBuffer();
        sb.append(Xmin).append(",").append(Ymin).append(",").append(Xmax).append(",").append(Ymax);
        return sb.toString();
    }

    public String toFilenameString() {
        StringBuffer sb = new StringBuffer();
        sb.append(Xmin).append("_").append(Ymin).append("_").append(Xmax).append("_").append(Ymax);
        return sb.toString();
    }

    public Double getDeltaX() {
        return Xmax - Xmin;
    }

    public Double getDeltaY() {
        return Ymax - Ymin;
    }

}
